package puyu.manage.service.sample.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import puyu.manage.service.common.config.BaseController;
import puyu.manage.service.constant.AjaxResult;
import puyu.manage.service.sample.service.SampleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 样品表(PuyuTSample)表控制层
 *
 * @author makejava
 * @since 2024-06-17 14:51:41
 */
@RestController
@Api(tags = "样品数据处理")
@RequestMapping("/sample")
public class SampleController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private SampleService sampleService;


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "样品二维码单条查询")
    @GetMapping("/queryById/{id}")
    public AjaxResult queryById(@PathVariable("id") String id) {
        return AjaxResult.success(sampleService.queryById(id));
    }


    /**
     * 样品二维码生成
     *
     * @return 编辑结果
     */
    @ApiOperation(value = "样品二维码生成(视频上传)")
    @PostMapping(value = "/editSampleCode")
    public AjaxResult editSampleCode(@ApiParam(name="params",
            value="参数集合:datas-页面需要修改数据;",required=true) @RequestParam Map<String,Object> params) throws Exception {
        //修改样品状态为生成状态。插入二维码地址和时间
        return AjaxResult.success(this.sampleService.editSampleCode(params));
    }

    /**
     * 样品试验视频上传
     *
     * @return 编辑结果
     */
    @ApiOperation(value = "样品试验视频上传")
    @PostMapping(value = "/editSampleVideo")
    public AjaxResult editSampleVideo(@ApiParam(name="params",
            value="参数集合:datas-页面需要修改数据;",required=true) @RequestParam Map<String,Object> params, MultipartFile file) throws Exception {
        //修改样品视频状态、视频上传地址和开始结束时间
        return AjaxResult.success(this.sampleService.editSampleVideo(params,file));
    }

    /**
     * 样品二维码扫码次数增加
     *
     */
    @ApiOperation(value = "样品二维码扫码次数增加")
    @GetMapping(value = "/updateSampleNum/{id}")
    public AjaxResult updateSampleNum(@PathVariable("id") String id) {
        //修改样品状态为生成状态。插入二维码地址和时间(视频状态、视频上传地址和开始结束时间)
        return AjaxResult.success(this.sampleService.updateSampleNum(id));
    }

    /**
     * 编辑数据
     *
     * @return 编辑结果
     */
    @ApiOperation(value = "批量样品二维码生成(视频上传)")
    @PostMapping(value = "/editSampleList")
    public AjaxResult editSampleList(@ApiParam(name="params",
            value="参数集合:datas-页面需要修改数据;",required=true) @RequestParam Map<String,Object> params, MultipartFile[] files) {
        //修改样品状态为生成状态。插入二维码地址和时间(视频状态、视频上传地址和开始结束时间)
        return AjaxResult.success(this.sampleService.updateList(params,files));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @ApiOperation(value = "删除视频")
    @DeleteMapping("/deleteById/{id}")
    public AjaxResult deleteById(@PathVariable("id") String id) {
        return AjaxResult.success(sampleService.deleteById(id));
    }

}

